package com.sl.au.repository;

import com.sl.au.entity.Account;
import com.sl.au.entity.PaymentInitial;
import com.sl.au.entity.User;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**应收账计划初始化
 * Created by RX on 2016/11/25.
 */
@Transactional(readOnly = true)
public interface PaymentInitialRepository extends JpaRepository<PaymentInitial, String> {
      /**
       * 得到应收账计划
       * @param contractId
       * @param contractType
       * @return
       */
      @Query("select p from PaymentInitial p where p.contractId = ?1 and p.contractType=?2 order by p.createTime asc ")
      List<PaymentInitial> findByContractIdAndContractType(String contractId,String contractType);

      /**
       * 查询是否存在应收账计划
       * @param contractId
       * @return
       */
      @Query("select p from PaymentInitial p where p.contractId = ?1")
      List<PaymentInitial> findByContractId(String contractId);

      /**
       * 得到应收账计划数据条数
       * @param contractId
       * @return
       */
      @Query(" select count(*) as num from PaymentInitial p where p.contractId = ?1")
      Long getPaymentScheduleCount(String contractId);
      /**
       * 得到人员下拉框
       * @param userArea
       * @return
       */
      @Query("select u from User u where u.saleArea.superior=?1 ")
      List<User> getUserList(String userSuperior);

      @Query("select u from User u where u.empLogin.name=?1 ")
	User getUserName(String name);
}
